package com.test.mchelepesa.dialog_rice;

import static android.view.View.GONE;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.test.mchelepesa.R;
import com.test.mchelepesa.util_rice.http_rice.HttpManager_rice;

public class RequestFailedDialog extends Dialog {

    private final boolean style2Flag;
    private final Runnable reloadRunnable;

    public RequestFailedDialog(Context context, Runnable reloadRunnable){
        super(context);
        this.style2Flag = false;
        this.reloadRunnable = reloadRunnable;
    }

    public RequestFailedDialog(Context context, boolean style2Flag, Runnable reloadRunnable){
        super(context);
        this.style2Flag = style2Flag;
        this.reloadRunnable = reloadRunnable;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_request_failed);

        getWindow().setBackgroundDrawableResource(R.color.trans);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        TextView desc1Tv = findViewById(R.id.request_failed_tv_desc_1);
        TextView desc2Tv = findViewById(R.id.request_failed_tv_desc_2);
        Button reloadBtn = findViewById(R.id.request_failed_btn_reload);

        if (style2Flag){
            desc1Tv.setText(getContext().getString(R.string.request_failed_desc_3));
            desc2Tv.setVisibility(GONE);
        }

        reloadBtn.setOnClickListener(v -> {
            HttpManager_rice.getInstance().saveUserBuriedPoint("DIALOG_RELOAD_RELOAD_CLICK");
            dismiss();
            if (reloadRunnable!=null) reloadRunnable.run();
        });

    }

}
